home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef EditorUtilities_H
- #define EditorUtilities_H
-
- #include <UKeyFilters.h>
-
- #include <MixedMode.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Files.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <QuickDrawText.h>
- #include <TextUtils.h>
- #include <Disks.h>
-
- #define kEmptyString (ConstStr255Param)"\p"
-
- // Key definitions.
- #define kUpArrowKey 0x1E
- #define kDownArrowKey 0x1F
- #define kRightArrowKey 0x1D
- #define kLeftArrowKey 0x1C
- #define kPageUpKey 0x0B
- #define kPageDownKey 0x0C
- #define kHomeKey 0x01
- #define kEndKey 0x04
- #define kHelpKey 0x72
- #define kTabKey 0x09
- #define kBackspaceKey 0x08
- #define kFwdDeleteKey 0x7F
- #define kReturnKey 0x0d
- #define kEnterKey 0x03
- #define kEscapeKey 0x1B
- #define kCancelKey 0x2E
-
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // class TRsrcHandle - class for reading and writing complex structured resources
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- class TRsrcHandle {
- public:
- Handle fRsrcHandle;
- SInt32 fCurPos; /* 1 is first position */
-
- TRsrcHandle();
- TRsrcHandle( Handle pInitilizedHandle );
- TRsrcHandle( Ptr pInitilizedPtr );
-
- virtual ~TRsrcHandle();
-
- // -- RESOURCE CREATION AND WRITING METHODS
- void AppendLong( SInt32 pTheLong );
- void AppendShort( SInt16 pTheShort );
- void AppendStr255( Str255 pTheStr255 );
- void AppendStr255WithoutPadByte( Str255 pTheStr255 );
- void AppendStr255AsData( Str255 pTheStr255 );
- void AppendStr255FromHandle( Handle pTheHandle );
- void AppendHandle( Handle pTheHandle );
-
- Handle GetRsrcHandle() { return fRsrcHandle; };
-
- void Write( SInt16 pFileRefNum,
- OSType pRsrcType,
- SInt16 pRsrcID );
-
-
- // -- RESOURCE READING METHODS
- SInt32 ReadLong();
- SInt16 ReadShort();
- SInt16 ReadByteIntoShort();
- void ReadPStrIntoStr255( Str255 outStr255 );
- Handle ReadPStrIntoHandle();
- void ReadChunk( Ptr pDest,
- SInt32 pSize );
-
- void SetPos( SInt32 pNewPos ) { (fCurPos = pNewPos); };
- Boolean PastEnd() { return (fCurPos > GetHandleSize( fRsrcHandle ) ); };
-
- };
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Global Routines
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
-
- SInt16 PStrCmp( ConstStr255Param p2, ConstStr255Param p1 );
-
- void PStrConcat( unsigned char* dst, const unsigned char* src );
-
- void PStrCopy( Str255 p2, ConstStr255Param p1 );
-
- void GetIndStringWithParam( Str255 theString,
- short strListID,
- short index,
- ConstStr255Param pParamText0,
- ConstStr255Param pParamText1,
- ConstStr255Param pParamText2,
- ConstStr255Param pParamText3 );
-
- void WriteStringResource( SInt16 inRsrcID, Str255 inString );
-
- void WriteStringListResourceIndex( SInt16 inFileRefNum, Str255 inString, SInt16 inRsrcID, SInt16 inIndex );
-
- void ResetResListResource( SInt16 inFileRefNum, SInt16 inResListRsrcID );
-
- void AppendToResListResource( SInt16 inFileRefNum, SInt16 inResListRsrcID, ResType inRsrcType, SInt16 inRsrcID );
-
- SInt16 GetUniqueIDForResType( SInt16 inFileRefNum, ResType theResType );
-
- void DeleteResource( SInt16 inFileRefNum, ResType inRsrcType, SInt16 inRsrcID );
-
- OSErr GetFileNameFromFileRefID( SInt16 inFileRefID, Str255 outFileName );
-
- EKeyStatus PrintingCharWithReturnField(const EventRecord &inKeyEvent );
-
- EKeyStatus SignedIntegerField(const EventRecord &inKeyEvent );
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Exceptions Handling Routines
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
- //----------------------------------------------------------------------------------------
- // This macro can be called on any variable to keep it out of a register. It is
- // used specifically in exception handling. Kludge to be used till volatile or
- // C++ exception handling is implemented.
- //----------------------------------------------------------------------------------------
-
- #define VOLATILE(a) ((void) &a)
-
- //
- // try/catch/throw usage:
- //
- // Advantage: Supported by the compiler, so it's portable
- // Disadvantage: Most of our compilers don't provide exception handling
- //
- // try
- // {
- // // do something
- // FailErr(SomeFnReturningOSErr()); // "throw" is unconditional, so we still need a FailErr
- // }
- // catch(OSErr err)
- // {
- // // clean up
- // throw(err);
- // }
- //
-
- void FailErr(OSErr);
- void FailMemError();
- void FailResError(); // resNotFound is OK
- void FailNil(void*);
- void FailResourceNil(Handle); // checks QuickResError, and resource for NIL
-
-
- //----------------------------------------------------------------------------------------
- // FailErr:
- //----------------------------------------------------------------------------------------
- inline void FailErr(OSErr error)
- {
- if( error != noErr )
- throw( error );
- }
-
-
- //----------------------------------------------------------------------------------------
- // FailMemError:
- //----------------------------------------------------------------------------------------
- inline void FailMemError()
- {
- OSErr error = MemError();
- if (error != noErr)
- throw( error );
- }
-
- //----------------------------------------------------------------------------------------
- // FailNil:
- //----------------------------------------------------------------------------------------
- inline void FailNil(void *pointer)
- {
- if (pointer == nil)
- throw( memFullErr);
- }
-
- //----------------------------------------------------------------------------------------
- // FailResError:
- //
- // resNotFound is OK
- //----------------------------------------------------------------------------------------
- inline void FailResError()
- {
- OSErr error = ResError();
-
- if ((error != noErr) && (error != resNotFound))
- throw( error );
- }
-
- //----------------------------------------------------------------------------------------
- // FailResourceNil:
- //----------------------------------------------------------------------------------------
- inline void FailResourceNil(Handle resource)
- {
- OSErr error = ResError();
-
- if ((error != noErr) && (error != resNotFound))
- throw( error );
- else if (resource == nil)
- throw( resNotFound );
- }
-
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Class LShortComparator
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
-
- class LShortComparator : public LComparator {
- public:
- LShortComparator() { }
- virtual ~LShortComparator() { }
-
- virtual Int32 Compare(
- const void* inItemOne,
- const void* inItemTwo,
- Uint32 inSizeOne,
- Uint32 inSizeTwo) const;
-
- virtual Boolean IsEqualTo(
- const void* inItemOne,
- const void* inItemTwo,
- Uint32 inSizeOne,
- Uint32 inSizeTwo) const;
-
- static LShortComparator* GetComparator();
-
- protected:
- static LShortComparator* sShortComparator;
- };
-
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Class LRsrcTypeAndIDComparator
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
-
- struct RsrcTypeAndID
- {
- ResType fRsrcType;
- SInt16 fRsrcID;
- };
- typedef struct RsrcTypeAndID RsrcTypeAndID;
-
- class LResTypeAndIDComparator : public LComparator {
- public:
- LResTypeAndIDComparator() { }
- virtual ~LResTypeAndIDComparator() { }
-
- virtual Int32 Compare(
- const void* inItemOne,
- const void* inItemTwo,
- Uint32 inSizeOne,
- Uint32 inSizeTwo) const;
-
- virtual Boolean IsEqualTo(
- const void* inItemOne,
- const void* inItemTwo,
- Uint32 inSizeOne,
- Uint32 inSizeTwo) const;
-
- static LResTypeAndIDComparator* GetComparator();
-
- protected:
- static LResTypeAndIDComparator* sResTypeAndIDComparator;
- };
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Editor calling definitions
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
-
- extern "C"{
- struct EditorLibProcParamBlock
- {
- SInt16 fFormatNum;
- QDGlobals* fQDGlobals;
- SInt16 fFileRefNum;
- SInt16 fPreferenceRsrcID;
- SInt16 fResListRsrcID;
- };
- typedef struct EditorLibProcParamBlock *EditorLibProcParamBlockPtr;
-
- typedef SInt32 (*EditorLibProcPtr)( EditorLibProcParamBlockPtr inEditorLibProcParamBlockPtr );
- }
-
- #endif